<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :edit="edit" :checkedit="checkedit" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {
		buildSubFormData,
		subOnLoad,
		changeEditor,
		configSelectData
	} from '../../../static/js/formUtil.js';
	import {
		ignoreHtml,
		ptFloat,
		minusF,
		getDateStr
	} from '@/static/js/common.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				customerOwnerCacheKey:'rps-xz-customer-title6-customerOwner-cache'
			})
		},
		methods:{
			onSelectPost(item){
				let _that = this
				_that.$refs.autoform.formdata.instId = item.instId
				_that.$refs.autoform.formdata.instName = item.instName
			},
			getPosComboboxByUser(id){
				let _that = this
				_that.om.request(
					"customer/getPosComboboxByUser",
					{
						userId:id
					}
				).then(res=>{
					_that.$refs.autoform.changeEditor("title6","postId","data",configSelectData(res,'id','postName'))
					if(!_that.$refs.autoform.formdata.postId){
						_that.$refs.autoform.initSelectVal("title6","postId")
					}else{
						_that.$refs.autoform.initSelectIndex("title6","postId")
					}
				})
			},
			getWorkPhone(id){
				let _that = this
				_that.om.request(
					"customer/getWorkPhone",
					{
						userId:id
					}
				).then(res=>{
					if(res.value){
						_that.$refs.autoform.formdata.ownerPhone = res.value
					}
				})
			},
			initload(){
				let _that = this
				let arr = [
					this.om.request(
						"dictZero/findYesNoList"
					)
				] 
				Promise.all(arr).then(res=>{
					_that.$refs.autoform.changeEditor("title6","cruxCustomerFlag","data",configSelectData(res[0],"value","name"))
					_that.$refs.autoform.initSelectIndex("title6","cruxCustomerFlag")
				})
			},
			
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
				if (e.configDataCacheKey) {
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							//if (res.data && res.data instanceof Array) {
							if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
								_that.autoformdata = res.data
							}
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							changeEditor("title6","customerOwnerId","isSearchUser",true,_that.autoformdata)
							changeEditor("title6","customerOwnerId",{
								link:'../../public/searchUser/searchUser',
								"linkParam":{
									cachename: _that.customerOwnerCacheKey,
									isSingle:true
								}
							},null,_that.autoformdata)
							_that.initload()
							if(_that.formdata.customerOwnerId){
								_that.getPosComboboxByUser(_that.formdata.customerOwnerId)
							}
						}
					})
				}
			})
		},
		onShow() {
			let _that = this
			if (_that.$refs.autoform) {
				uni.getStorage({
					key:_that.customerOwnerCacheKey,
					success:(res)=>{
						if(res.data){
							let d = res.data[0]
							let formdata = _that.$refs.autoform.formdata
							formdata.customerOwnerId = d.id
							formdata.customerOwner = d.username
							_that.getWorkPhone(d.id)
							_that.getPosComboboxByUser(d.id)
							uni.removeStorage({
								key:_that.customerOwnerCacheKey
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
</style>
